<?
include("../lib/config.php");
//$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];
$category		= $HTTP_GET_VARS['category'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("SELECT * FROM S_LP_Cat_Nilai WHERE category='$category'",$conn);
	$row	= mssql_fetch_array($query);
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Save";
}

include("../header.php");
?>
<script type="text/javascript" language="javascript">

	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){
		if(document.FEmployee.category.value == "")
		{
			alert("Field : Kategori Penilaian tidak boleh kosong ...");
			document.FEmployee.category.focus();
			return false;
		}
		
		document.FEmployee.submit();
	}
	
	function cek_all(){
		var count = document.forms[0].elements.length;
		for (i=0; i<count; i++) 
		{
			var element = document.forms[0].elements[i]; 
			//if (document.form1.check1.checked == true) 
			//{ 
			if (element.type == "checkbox") 
			{ 
				element.checked=true; 
			} 
			//} 
			else 
			{ 
				element.checked=false; 
			}
		}
	}
	
	function not_cek_all(){
		var count = document.forms[0].elements.length;
		for (i=0; i<count; i++) 
		{
			var element = document.forms[0].elements[i]; 
			//if (document.form1.check1.checked == true) 
			//{ 
			if (element.type == "checkbox") 
			{ 
				element.checked=false; 
			} 
			//} 
			else 
			{ 
				element.checked=true; 
			}
		}
	}
</script>
</head>
<form name="FEmployee" method="post" action="<?=$Faction?>">
<table width="100%" class="no_border">
 <tr>
  <td colspan="2">
	<table width="100%" style="border:none;">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;&nbsp;<b>KATEGORI UNSUR LP2</td>
	</tr>
	</table>
  </td>
  </td>
 </tr>
 <tr>
  <td>&nbsp;</td>
 </tr>
 <tr>
  <td>
 <table cellpadding="2" cellspacing="0" width="100%">
 <tr>
  <td width="150">Kategori Penilaian:</td>
  <td><input type="text" name="category" maxlength="50" value="<?=$row[category]?>" 
  <?
  if($op == "edit")
  { echo"readonly"; } 
  else
  { }
  ?> /> <span class="required">*</span></td>
 </tr>
 <tr>
  <td colspan="2">
  <form>
  <fieldset><legend>Item Penilaian</legend>
  	<table>
	<?
		$scatlp = mssql_query("SELECT * FROM MstUnsurLP2 ORDER BY UnsurName");
		while($rcat = mssql_fetch_array($scatlp)){
	?>
	 <tr>
	  <td><label><input type="checkbox" name="id_unsur[]" value="<?=$rcat[UnsurID]?>"
	  <?
	  	$sss = mssql_query("SELECT * FROM S_LP_Cat_Nilai WHERE category='$row[category]'",$conn);
		while($rrr = mssql_fetch_array($sss)){
		  	if($rcat[UnsurID] == $rrr[unsur_penilai]){
				echo"checked";
			}
		}
	  ?>
	   /> <?=$rcat[UnsurName]?></label></td>
	 </tr>
	<?
		}
	?>
	 <tr>
	  <td colspan="2"><br />
	  &nbsp;<a href="#" onclick="cek_all()" style="color:#006600; font-weight:bold;">Checklist Semua</a> | <a href="#" onclick="not_cek_all()" style="color:#006600; font-weight:bold;">Unchecklist Semua</a>
	  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	  <input type="hidden" value="cat_lp2" name="cat" />
	  <input type="reset" class="button" value="Reset" />
	  <input type="button" value="Simpan" class="button" onclick="Javascript:Validate();" />
	  </td>
	 </tr>
	</table>
   </fieldset>
   </form>
  </td>
 </tr>
</table>
</form>
</td>
</tr>
<tr>
 <td colspan="2" style="border:none;"><? include("../footer.php"); ?></td>
</tr>
</table>
</body>
</html>
<script type="text/javascript">
//ar f = document.forms[0];
//MaskInput(f.kode_penilaian,"999");
//]]>
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>